package org.lyh.gift.exception;

import lombok.extern.slf4j.Slf4j;
import org.lyh.gift.util.AjaxResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalException {
    //预期异常
    @ExceptionHandler(BusinessException.class)
    public AjaxResult businessException(BusinessException e){
        log.error("业务异常:{}",e);
        return AjaxResult.me().setSuccess(false).setMessage("业务异常:"+e.getMessage());
    }
    //意外异常
    @ExceptionHandler(Exception.class)
    public AjaxResult handlerException(Exception e){
        // 记录异常日志
        log.error("系统异常：{}",e);
        // 返回提示信息
        return AjaxResult.me().setSuccess(false).setMessage("系统异常:"+e.getMessage());
    }
}
